from django.db import models

# Create your models here.
from users.models import User
import sys

from utils.qiniu_storage import QiNiuStorage

print(sys.path)
from utils.models import BaseModel


class ArticlCategory(BaseModel):
    """分类模型类"""
    name= models.CharField(max_length=40, verbose_name='分类名')
    alias=models.CharField(max_length=40,verbose_name='分类别名')
    is_delete = models.IntegerField(verbose_name='是否被删除',null=True,default=0)
    class Meta:
        db_table = 'tb_categories'
        verbose_name = '分类'
        verbose_name_plural = verbose_name
        ordering = ['id']

    def __str__(self):
        return self.name


class Article(BaseModel):
    """文章模型类"""
    title=models.CharField(max_length=80,verbose_name='文章标题')
    content= models.TextField(verbose_name='文章内容')
    cover_img=models.CharField(max_length=80,verbose_name='封面url')
    pub_date = models.DateTimeField(auto_now=True, verbose_name="发布时间")
    state = models.CharField(max_length=20,verbose_name='状态')
    is_delete = models.IntegerField(verbose_name='是否被删除',null=True,default=0)
    cate_name = models.ForeignKey(ArticlCategory,related_name='cate_articles')
    author = models.ForeignKey(User,related_name='articles',verbose_name='作者')
    cover_img = models.ImageField(storage=QiNiuStorage(),verbose_name='封面')
    class Meta:
        db_table = 'tb_articles'
        verbose_name = '文章'
        verbose_name_plural = verbose_name
        ordering = ['id']

    def __str__(self):
        return self.title